home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / X70GKM (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  3.3 KB  |  108 lines

  1. package com.sun.java.swing.border;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Graphics;
  6. import java.awt.Insets;
  7.  
  8. public class BevelBorder extends AbstractBorder {
  9.    public static final int RAISED = 0;
  10.    public static final int LOWERED = 1;
  11.    protected int bevelType;
  12.    protected Color highlightOuter;
  13.    protected Color highlightInner;
  14.    protected Color shadowInner;
  15.    protected Color shadowOuter;
  16.  
  17.    public BevelBorder(int bevelType) {
  18.       this.bevelType = bevelType;
  19.    }
  20.  
  21.    public BevelBorder(int bevelType, Color highlight, Color shadow) {
  22.       this(bevelType, highlight.darker(), highlight, shadow, shadow.brighter());
  23.    }
  24.  
  25.    public BevelBorder(int bevelType, Color highlightOuter, Color highlightInner, Color shadowOuter, Color shadowInner) {
  26.       this(bevelType);
  27.       this.highlightOuter = highlightOuter;
  28.       this.highlightInner = highlightInner;
  29.       this.shadowOuter = shadowOuter;
  30.       this.shadowInner = shadowInner;
  31.    }
  32.  
  33.    public int getBevelType() {
  34.       return this.bevelType;
  35.    }
  36.  
  37.    public Insets getBorderInsets(Component c) {
  38.       return new Insets(2, 2, 2, 2);
  39.    }
  40.  
  41.    public Color getHighlightInnerColor(Component c) {
  42.       return this.highlightInner != null ? this.highlightInner : c.getBackground().brighter();
  43.    }
  44.  
  45.    public Color getHighlightOuterColor(Component c) {
  46.       return this.highlightOuter != null ? this.highlightOuter : c.getBackground().brighter().brighter();
  47.    }
  48.  
  49.    public Color getShadowInnerColor(Component c) {
  50.       return this.shadowInner != null ? this.shadowInner : c.getBackground().darker();
  51.    }
  52.  
  53.    public Color getShadowOuterColor(Component c) {
  54.       return this.shadowOuter != null ? this.shadowOuter : c.getBackground().darker().darker();
  55.    }
  56.  
  57.    public boolean isBorderOpaque() {
  58.       return true;
  59.    }
  60.  
  61.    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  62.       if (this.bevelType == 0) {
  63.          this.paintRaisedBevel(c, g, x, y, width, height);
  64.       } else if (this.bevelType == 1) {
  65.          this.paintLoweredBevel(c, g, x, y, width, height);
  66.       }
  67.  
  68.    }
  69.  
  70.    protected void paintLoweredBevel(Component c, Graphics g, int x, int y, int width, int height) {
  71.       Color oldColor = g.getColor();
  72.       g.translate(x, y);
  73.       g.setColor(this.getShadowInnerColor(c));
  74.       g.drawLine(0, 0, 0, height - 1);
  75.       g.drawLine(1, 0, width - 1, 0);
  76.       g.setColor(this.getShadowOuterColor(c));
  77.       g.drawLine(1, 1, 1, height - 2);
  78.       g.drawLine(2, 1, width - 2, 1);
  79.       g.setColor(this.getHighlightOuterColor(c));
  80.       g.drawLine(1, height - 1, width - 1, height - 1);
  81.       g.drawLine(width - 1, 1, width - 1, height - 2);
  82.       g.setColor(this.getHighlightInnerColor(c));
  83.       g.drawLine(2, height - 2, width - 2, height - 2);
  84.       g.drawLine(width - 2, 2, width - 2, height - 3);
  85.       g.translate(-x, -y);
  86.       g.setColor(oldColor);
  87.    }
  88.  
  89.    protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int width, int height) {
  90.       Color oldColor = g.getColor();
  91.       g.translate(x, y);
  92.       g.setColor(this.getHighlightOuterColor(c));
  93.       g.drawLine(0, 0, 0, height - 1);
  94.       g.drawLine(1, 0, width - 1, 0);
  95.       g.setColor(this.getHighlightInnerColor(c));
  96.       g.drawLine(1, 1, 1, height - 2);
  97.       g.drawLine(2, 1, width - 2, 1);
  98.       g.setColor(this.getShadowOuterColor(c));
  99.       g.drawLine(1, height - 1, width - 1, height - 1);
  100.       g.drawLine(width - 1, 1, width - 1, height - 2);
  101.       g.setColor(this.getShadowInnerColor(c));
  102.       g.drawLine(2, height - 2, width - 2, height - 2);
  103.       g.drawLine(width - 2, 2, width - 2, height - 3);
  104.       g.translate(-x, -y);
  105.       g.setColor(oldColor);
  106.    }
  107. }
  108.